package app.texas.com.devilfishhouse.weight.iosDialog;

import android.content.Context;
import android.net.Uri;
import android.os.Environment;
import android.view.View;

import com.jph.takephoto.app.TakePhoto;

import java.io.File;
import java.util.List;


/**
 * Created by solin on 2018/6/11.
 */

public class IosDialogHelper {

    /**
     * 显示一个按钮的弹窗  带监听的
     */
    public void showOneButton(Context context, String msg, View.OnClickListener listener) {
        new AlertDialog(context).builder()
                .setMsg(msg)
                .setNegativeButton("确定", listener).show();
    }

    /**
     * 显示一个按钮  不带监听
     *
     * @param context
     * @param msg
     */
    public void showOneButton(Context context, String msg) {
        new AlertDialog(context).builder()
                .setMsg(msg)
                .setNegativeButton("确定", new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {

                    }
                }).show();
    }

    /**
     * 两个按钮的 提示框
     *
     * @param context
     * @param title
     * @param msg
     * @param listener
     */
    public static void showTwoButtonDialog(Context context, String title, String msg, View.OnClickListener listener) {
        new AlertDialog(context).builder()
                .setTitle(title)
                .setMsg(msg)
                .setPositiveButton("确定", listener)
                .setNegativeButton("取消", new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {

                    }
                }).show();
    }

    /**
     * 拍照底部弹窗
     *
     * @param context
     */
    public static void showSelectPhotoDialog(Context context, final TakePhoto takePhoto) {
        new ActionSheetDialog(context).builder()
                .setCancelable(false)
                .setCanceledOnTouchOutside(false)
                .setTitle("选择图片")
                .addSheetItem("拍照", ActionSheetDialog.SheetItemColor.Blue, new ActionSheetDialog.OnSheetItemClickListener() {
                    @Override
                    public void onClick(int which) {

                        File file = new File(Environment.getExternalStorageDirectory(), "/temp/" + System.currentTimeMillis() + ".jpg");
                        if (!file.getParentFile().exists()) file.getParentFile().mkdirs();
                        Uri imageUri = Uri.fromFile(file);
                        takePhoto.onPickFromCapture(imageUri);
                    }
                })
                .addSheetItem("打开相册", ActionSheetDialog.SheetItemColor.Blue, new ActionSheetDialog.OnSheetItemClickListener() {
                    @Override
                    public void onClick(int which) {
                        takePhoto.onPickMultiple(1);
                    }
                })
                .show();
    }

    /**
     * 分享给好友
     *
     * @param context
     * @param qqListener
     */
    public static void showShardDialog(Context context, ActionSheetDialog.OnSheetItemClickListener qqListener) {
        new ActionSheetDialog(context).builder()
                .setCancelable(false)
                .setCanceledOnTouchOutside(false)
                .setTitle("分享")
                .addSheetItem("QQ", ActionSheetDialog.SheetItemColor.Blue, qqListener)
                .addSheetItem("QQ空间", ActionSheetDialog.SheetItemColor.Blue, qqListener)
                .addSheetItem("微信", ActionSheetDialog.SheetItemColor.Blue, qqListener)
                .addSheetItem("朋友圈", ActionSheetDialog.SheetItemColor.Blue, qqListener)
                .show();
    }

    /**
     * 性别
     *
     * @param context
     */
    public static void showSexDialog(Context context, ActionSheetDialog.OnSheetItemClickListener nanListener,
                                     ActionSheetDialog.OnSheetItemClickListener nvlistener) {
        new ActionSheetDialog(context).builder()
                .setCancelable(false)
                .setCanceledOnTouchOutside(false)
                .setTitle("选择性别")
                .addSheetItem("男", ActionSheetDialog.SheetItemColor.Blue, nanListener)
                .addSheetItem("女", ActionSheetDialog.SheetItemColor.Blue, nvlistener)
                .show();
    }

    /**
     * 显示List集合的列表
     *
     * @param context
     */
    public static void showListDialog(Context context, String title, List<String> itemString, ActionSheetDialog.OnSheetItemClickListener itemClickListener) {
        ActionSheetDialog dialog = new ActionSheetDialog(context).builder();
        dialog.setCancelable(false);
        dialog.setCanceledOnTouchOutside(false);
        dialog.setTitle(title);
        for (String str : itemString) {
            dialog.addSheetItem(str, ActionSheetDialog.SheetItemColor.Blue, itemClickListener);
        }
        dialog.show();
    }

//    /**
//     * 显示List集合的列表 区域列表
//     *
//     * @param context
//     */
//    public static void showListDialogArea(Context context, String title, List<AreaBean> itemString, ActionSheetDialog.OnSheetItemClickListener itemClickListener) {
//        ActionSheetDialog dialog = new ActionSheetDialog(context).builder();
//        dialog.setCancelable(false);
//        dialog.setCanceledOnTouchOutside(false);
//        dialog.setTitle(title);
//        for (AreaBean str : itemString) {
//            dialog.addSheetItem(str.getTitle(), ActionSheetDialog.SheetItemColor.Blue, itemClickListener);
//        }
//        dialog.show();
//    }

    /**
     * 显示加载中的弹窗
     *
     * @param context
     * @return
     */
    public static LoadingDialog showLoadingDialog(Context context) {
        LoadingDialog.Builder builder = new LoadingDialog.Builder(context)
                .setMessage("加载中...")
                .setCancelable(false);
        final LoadingDialog dialog = builder.create();
        dialog.show();
        return dialog;
    }

    /**
     * 可自定义内容
     *
     * @param context
     * @param msg
     * @return
     */
    public static LoadingDialog showLoadingDialog(Context context, String msg) {
        LoadingDialog.Builder builder = new LoadingDialog.Builder(context)
                .setMessage(msg)
                .setCancelable(false);
        final LoadingDialog dialog = builder.create();
        dialog.show();
        return dialog;
    }
}
